package lrz.shiftplanner.staff;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

import lrz.shiftplanner.application.MainWindow;
import lrz.shiftplanner.components.NamePanel;
import lrz.shiftplanner.components.Selector;

public class Person implements Comparable<Person> {

	private String name;

	// Number of shifts that OP has already taken
	private int shiftsTaken;
	// Number of shifts OP should take each month
	private int shiftsTotal;
	// Number of standby shifts
	private int standby;
	// Predefined order within the operator group (should be set up at the beginning of a session)
	private int index;
	// Handle "Skip" mechanism
	private int wait;
	// Flag that indicates that the operator has finished 
	public boolean finished;

	//transient private ArrayList<Selector> selectors = new ArrayList<Selector>();
	//transient private NamePanel namePanel;

	public Person(String name, int capacity, int index) {
		this.name = name;
		this.shiftsTaken = 0;
		this.shiftsTotal = capacity;
		this.index = index;
		finished = false;
		wait = 0;
		//namePanel = new NamePanel(this, mainWindow);
	}

//	public NamePanel getNamePanel() {
//		return namePanel;
//	}
	
	public boolean equals(Person person) {
		return name.equals(person.name);
	}
		
	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getShiftNumber() {
		return shiftsTaken;
	}

	public void setShiftNumber(int shiftNumber) {
		this.shiftsTaken = shiftNumber;
	}

	public int getOrder() {
		if (finished)
			return 1000000;
		return ((shiftsTaken) * (shiftsTotal == 10 ? 1 : 2) + wait) * 100 + index;
	}

	public void incShift(int i, boolean isStandby) {
		if (isStandby)
			standby += i;
		else
			shiftsTaken += i;

	}
	
//	public boolean hasChoice() {
//		for (Selector s : selectors)
//			if (!s.getDay().getMissingStringShort().equals(""))
//				return true;
//		return false;
//
//	}

//	public void addSelector(Selector s) {
//		selectors.add(s);
//	}


	public void waitRound() {
		wait++;
	}

	public String getName() {
		return name;
	}

	public int getCapacity() {
		return shiftsTotal;
	}

	public int getStandby() {
		return standby;
	}

	public void setStandby(int standby) {
		this.standby = standby;
	}

//	public static ArrayList<Person> getPersons(MainWindow m) {
//
//		File file = new File("Schichten/DefaultOrder.lrz");
//		Scanner s = null;
//		if (file.exists()) {
//
//		                            	try {
//				ArrayList<Person> persons;
//				persons = new ArrayList<Person>();
//				s = new Scanner(file);
//				s.useDelimiter(";");
//				int k = s.nextInt();
//				s.nextLine();
//
//				for (int i = 0; i < k; i++) {
//					Person p = new Person(s.next(), s.nextInt(), s.nextInt(), m);
//					s.nextLine();
//					p.finished = false;
//					persons.add(p);
//				}
//				return persons;
//			} catch (Exception e) {
//				e.printStackTrace();
//				return null;
//			}
//		} else {
//			System.out.println("Keine Standardreihenfolge-Datei gefunden!");
//			System.exit(-1);
//			
//			return null;
//		}
//
//	}

	@Override
	public String toString() {
		return getName();
	}

	@Override
	public int compareTo(Person arg0) {
		return Integer.valueOf(getOrder()).compareTo(
				Integer.valueOf(arg0.getOrder()));
	}
}
